package com.wangbo.box.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * java 提供的观察者接口
 */
public class JavaObserverPattern {

    static class ObserverA implements Observer{

        @Override
        public void update(Observable o, Object arg) {
            System.out.println("ob A");
        }
    }

    static class ObserverB implements Observer{

        @Override
        public void update(Observable o, Object arg) {
            System.out.println("ob B");
        }
    }


    static class RealObservable extends Observable{

        void set(){
            super.setChanged();
        }
    }


    public static void main(String[] args) {
        RealObservable observable = new RealObservable();
        observable.addObserver(new ObserverA());
        observable.addObserver(new ObserverB());
        observable.set();
        observable.notifyObservers();
    }


}
